package com.mairuide.bill.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.mairuide.openaccountinfo.pojo.OpenaccountInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import com.mairuide.bill.DealFlow;

/**
 * Created by 敲代码的卡卡罗特
 * on 2018/11/21 14:30.
 * 解析txt的工具类
 */
@Component
public class AnalysisTxtUtils {

    /**
     *
     * @author 刘中华
     * @date 2018/11/21 14:32
     * @param [file]
     * @return java.util.List<com.mairuide.bill.DealFlow>
     * @Description 解析南阳txt模板
     */
    public List<DealFlow> analysisNanYangTxt(MultipartFile file){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream);
            br = new BufferedReader(reader);
            String text = null;
            int i=0;
            while((text = br.readLine()) != null){
                if(i==0){
                    String[] titleArr = text.split("\\|");
                    i++;continue;
                }
                if(StringUtils.isNotBlank(text)&&text.contains("|")){
                    DealFlow dealFlow = new DealFlow();
                    String[] strings = text.split("\\|");
                    if(StringUtils.isBlank(strings[0])&&StringUtils.isNotBlank(strings[1])){
                        dealFlow.setAccountBodyCard(strings[1]);//交易主体卡号
                    }else{
                        dealFlow.setAccountBodyCard(strings[0]);//交易主体卡号
                    }
                    dealFlow.setAccountBodyNumber(strings[1]);//交易主体账号
                    Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(strings[2]));
                    if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                    dealFlow.setAccountMoney(new BigDecimal(strings[4]));//交易金额
                    if(dealFlow.getAccountMoney().compareTo(new BigDecimal(0))>0){
                        dealFlow.setSign(0);
                    }else{
                        dealFlow.setSign(1);
                    }
                    dealFlow.setSurplusMoney(new BigDecimal(strings[5]));//交易后余额
                    dealFlow.setAccountRivalCard(strings[7]);//交易对手卡号
                    dealFlow.setSerialNumber(strings[8]);//交易流水号
                    dealFlow.setAccountAddress(strings[11]);//交易地点
                    dealFlow.setContentAbstract(strings[13]);//摘要
                    list.add(dealFlow);
                }else{
                    continue;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    /**
     *
     * @author 刘中华
     * @date 2018/11/21 17:21
     * @param [file]
     * @return java.util.List<com.mairuide.bill.DealFlow>
     * @Description 解析邮政txt模板
     */
    public List<DealFlow> analysisYouZhengTxt(MultipartFile file,String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String text = null;
            int i=0;
            int k=0;
            int flag=0;
            HashMap<String, String> map = new HashMap<>();
            while((text = br.readLine()) != null){
                text=text.trim();
                i++;
                DealFlow dealFlow = new DealFlow();
                if(i==0||i==1||i==2){
                   continue;
                }
                String regEx = "(\\d+)";
                Pattern pat = Pattern.compile(regEx);
                if(i==3){
                    String[] split = text.split("\\s+");
                    String s1 = split[0].trim().split("：")[1];// 开户机构号
                    String s2 = split[1].trim().split("：")[1];//开户机构名称 account_body_bank
                    map.put("开户机构名称",s2);

                    continue;
                }
                if(i==4){
                    String[] split = text.split("\\s");
                    for (String s:split){
                        Matcher mat = pat.matcher(s);
                        if(mat.find()){
                            String s1 = mat.group(1); // 账号/ 卡号  account_body_card
                            map.put("账号",s1);
                        }
                    }
                    String name = split[split.length - 1].split("：")[1];//户名 account_body
                    dealFlow.setAccountBody(name);
                    map.put("户名",name);
                    continue;
                }
                if(i==5){
                    String[] split = text.split("：");
                    for (int j=0;j<split.length;j++){
                        switch (j) {
                            case 0 : break;
                            case 1 : String ss=split[j].split("\\s+")[0];break; // 子  账  号
                            case 2 : String dd=split[j].split("\\s+")[0];break; //子账 户 种类
                            case 3 : String dss=split[j].split("\\s+")[0];break;//存期/通知品种
                        }
                        String s1 = split[j].split("\\s+")[0];
                    }
                    continue;
                }
                if(i==6){
                    String[] split = text.split("：");
                    for (int j=0;j<split.length;j++){
                        switch (j) {
                            case 0 : break;
                            case 1 : map.put("币种",split[j].split("\\s+")[0]);break; //  币种 currency
                            case 2 : String dd=split[j].split("\\s+")[0];break; //资 金 形  态
                            case 3 : String dss=split[j].split("\\s+")[0];break;//账户状态
                        }
                        String s1 = split[j].split("\\s+")[0];
                    }
                    continue;
                }
                //下面是是开始循环主体，标题头跳过，隔行读取的业务逻辑
                if (text.contains("│")){
                    if (k==0){
                        k++;
                        //判断是否是奇数还是偶数，隔行读取
                        flag=i%2;
                        continue;
                    }
                    if (flag!=i%2) continue;
                    String[] split = text.split("│");
                    for (int v=0;v<split.length;v++){
                        if (StringUtils.isBlank(split[v])){
                            continue;
                        }
                        switch (v){
                            case 2:
                                Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(split[v]));
                                if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                                break;
                            //case 3:dealFlow.setTradeDate(split[v]);continue;//交易渠道
                            case 4:{
                                dealFlow.setContentAbstract(split[v]);
                                if("取款".equals(split[v])){
                                    dealFlow.setSign(1);
                                }else{
                                    dealFlow.setSign(0);
                                }
                                break;//摘要
                            }
                            case 5:dealFlow.setAccountMoney(new BigDecimal(split[v].trim().replaceAll(",","")));break;//交易金额
                            case 6:dealFlow.setSurplusMoney(new BigDecimal(split[v].trim().replaceAll(",","")));break;//账户余额
                            case 7:{
                                dealFlow.setAccountRivalNumber(split[v]);//对方账号
                                dealFlow.setAccountRivalCard(split[v]);//对方卡号
                                break;
                            }
                            //case 8:dealFlow.setAccountRivalNumber(split[v]);continue;//原子账号
                            case 9:dealFlow.setAccountAddress(split[v]);break;//交易机构名称
                        }
                    }
                    dealFlow.setAccountBodyBank(map.get("开户机构名称"));
                    dealFlow.setAccountBodyCard(map.get("账号"));
                    dealFlow.setAccountBody(map.get("户名"));
                    dealFlow.setCurrency(map.get("币种"));
                    list.add(dealFlow);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    /**
     *
     * @author 刘中华
     * @date 2018/11/22 14:40
     * @param [file, javaEncode]
     * @return java.util.List<com.mairuide.bill.DealFlow>
     * @Description 解析省农行txt模板
     */
    public List<DealFlow> analysisShengNongTingTxt(MultipartFile file,String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        String txt="ATM转账对手信息：";
        try {
            inputStream = file.getInputStream();
            reader = new InputStreamReader(inputStream, javaEncode);
            br = new BufferedReader(reader);
            String text = null;
            boolean next=false;
            DealFlow dealFlow = new DealFlow();
            while((text = br.readLine()) != null){

                text=text.trim();
                if (StringUtils.isBlank(text))continue;
                if (text.contains("--")){continue;}
                if (text.replaceAll(" ","").contains("号")){continue;}
                if (text.replaceAll(" ","").contains("交易")){continue;}
                if (txt.equals(text))next=true;
                if (!next){ //第一种规则

                    //解析第一行
                    if (isNumeric(text.replaceAll(" ",""))){
                        String[] split = text.split("\\s+");
                        if (split.length==6){//如果等于5，说明数据完整
                            dealFlow.setAccountBodyNumber(split[0]);//帐号
                            dealFlow.setAccountBodyCard(split[0]);//卡号
                            dealFlow.setAccountBodyCard(split[1]);//交易产品号
                            Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(split[2]+split[3]));
                            if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                            dealFlow.setSerialNumber(split[4]);//交易代码  传票号
                        }else if (split.length<6){
//                        System.out.println(Arrays.toString(split));
                            boolean flag=true;
                            for (int i=0;i<split.length;i++){
                                String s = split[i];
                                String s2="";
                                if (s.length()==8&&flag){
                                    s2 = split[i+1];
                                    flag=false;
                                }
                                if (i==0){
                                    dealFlow.setAccountBodyNumber(s);//帐号
                                    dealFlow.setAccountBodyCard(s);//卡号
                                }else {
                                    if (15<=s.length()&&20>=s.length()){
                                        dealFlow.setAccountBodyCard(s);//交易产品号
                                    }else if (s.length()==8&&s2.length()==6&&flag){
                                    	Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(s+s2));
                                    	if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                                    }else if (s.length()==8&&s2.length()!=6&&flag){
                                        Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(s));
                                        if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                                    }else if (s.length()==4){
                                        dealFlow.setSerialNumber(s);//交易代码  传票号
                                    }
                                }
                            }
                        }
                    }else if (text.replaceAll(" ","").contains(".")){
                        String[] split = text.split("\\s+");
                        dealFlow.setAccountMoney(new BigDecimal(split[0]));// 交易金额
                        dealFlow.setSurplusMoney(new BigDecimal(split[1]));// 交易后余额
                        dealFlow.setAccountAddress(split[1]);// 交易地点
                       // System.out.println(Arrays.toString(split));
                    }else if (!text.contains("。")){
                        String[] split = text.split("\\s+");
                        if (split.length==3){
                            dealFlow.setContentAbstract(split[1]);
                            dealFlow.setAccountRivalCard(split[2]);
                        }else if (split.length==2){
                            dealFlow.setContentAbstract(split[1]);
                        }
                        if ("现取".equals(dealFlow.getContentAbstract())){
                            dealFlow.setSign(1);
                        }else{
                            dealFlow.setSign(0);
                        }
//                        System.out.println(Arrays.toString(split));
                        if (dealFlow.getAccountBodyCard()==null)continue;
                        if (dealFlow.getAccountMoney()!=null&&dealFlow.getAccountMoney().compareTo(new BigDecimal(0))<0)dealFlow.setSign(1);
                        list.add(dealFlow);
                        dealFlow=new DealFlow();
                    }

                }else { //第二种规则
                    if (txt.equals(text))continue;
                    String[] split = text.split("\\s+");
                    //DealFlow dealFlow = new DealFlow();
                    Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(split[0]));
                    if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                    dealFlow.setAccountRivalNumber(split[1]);// 收款方账号
                    dealFlow.setAccountRivalCard(split[1]);// 收款方卡号
                    dealFlow.setAccountBodyNumber(split[2]);//付款方账号
                    dealFlow.setAccountBodyCard(split[2]);//付款方卡号
                    dealFlow.setAccountMoney(new BigDecimal(split[3]));//交易金额
                    list.add(dealFlow);
                    dealFlow=new DealFlow();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    public List<DealFlow> analysisShengNong1TingTxt(MultipartFile file,String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        try {
            inputStream = file.getInputStream();
            reader = new InputStreamReader(inputStream, javaEncode);
            br = new BufferedReader(reader);
            String text = null;
            while((text = br.readLine()) != null){
                if (text.contains("查询的账号是")){
                    String number = text.split("：")[1];
                    text = br.readLine();text = br.readLine();//读两行
                    String[] split = text.split("\\s+");
                    if (split.length==4){
                        for (int i=0;i<5;i++)text = br.readLine();
                        while(true){
                            text = br.readLine();
                            if ("".equals(text))break;
                            DealFlow deal = new DealFlow();
                            String[] split1 = text.split("\\s+");
                            Date date = DateUtils.getDate(split1[1]);
                            if (date!=null)deal.setTradeDate(new Timestamp(date.getTime()));
                            text = br.readLine();//第二行
                            String[] split2 = text.split("\\s+");
                            if (number.equals(split1[2])){
                                deal.setAccountBodyNumber(number);
                                deal.setAccountBodyCard(number);
                                deal.setAccountBody(split1[3]);
                                deal.setAccountRivalNumber(split2[1]);
                                deal.setAccountRivalCard(split2[1]);
                                deal.setAccountRival(split2[2]);
                                deal.setSign(0);
                            }else {
                                deal.setAccountBodyNumber(number);
                                deal.setAccountBodyCard(number);
                                deal.setAccountBody(split2[2]);
                                deal.setAccountRivalNumber(split1[2]);
                                deal.setAccountRivalCard(split1[2]);
                                deal.setAccountRival(split1[3]);
                                deal.setSign(1);
                            }
                            text = br.readLine();//第三行
                            String[] split3 = text.split("\\s+");
                            deal.setAccountMoney(new BigDecimal(split3[1]));

                            list.add(deal);

                        }

                    }else {
                        text = br.readLine();
                        while (true){
                            text = br.readLine();
                            String[] sp = text.split("\\s+");
                            if (sp.length!=6)break;
                            DealFlow dealFlow = new DealFlow();
                            Date date = DateUtils.getDate(sp[1]);
                            if (date!=null)dealFlow.setTradeDate(new Timestamp(date.getTime()));
                            if (number.equals(sp[2])){
                                dealFlow.setSign(1);
                                dealFlow.setAccountBodyNumber(number);
                                dealFlow.setAccountBodyCard(number);
                                dealFlow.setAccountRivalNumber(sp[3]);
                                dealFlow.setAccountRivalCard(sp[3]);
                            }else {
                                dealFlow.setSign(0);
                                dealFlow.setAccountBodyNumber(sp[3]);
                                dealFlow.setAccountBodyCard(sp[3]);
                                dealFlow.setAccountRivalNumber(sp[2]);
                                dealFlow.setAccountRivalCard(sp[2]);
                            }
                            dealFlow.setAccountMoney(new BigDecimal(sp[5]));
                            list.add(dealFlow);
                        }
                    }

                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    public List<DealFlow> analysisShengNong2TingTxt(MultipartFile file,String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        String txt="ATM转账对手信息：";
        try {
            inputStream = file.getInputStream();
            reader = new InputStreamReader(inputStream, javaEncode);
            br = new BufferedReader(reader);
            String text = null;
            boolean next=false;
            DealFlow dealFlow = new DealFlow();
            while((text = br.readLine()) != null){

                text=text.trim();
                if (StringUtils.isBlank(text))continue;
                if (text.contains("--")){continue;}
                if (text.replaceAll(" ","").contains("号")){continue;}
                if (text.replaceAll(" ","").contains("交易")){continue;}
                if (txt.equals(text))next=true;
                if (!next){ //第一种规则

                    //解析第一行
                    if (isNumeric(text.replaceAll(" ",""))){
                        String[] split = text.split("\\s+");
                        if (split.length==6){//如果等于5，说明数据完整
                            dealFlow.setAccountBodyNumber(split[0]);//帐号
                            dealFlow.setAccountBodyCard(split[0]);//卡号
                            dealFlow.setAccountBodyCard(split[1]);//交易产品号
                            Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(split[2]+split[3]));
                            if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                            dealFlow.setSerialNumber(split[4]);//交易代码  传票号
                        }else if (split.length<6){
//                        System.out.println(Arrays.toString(split));
                            boolean flag=true;
                            for (int i=0;i<split.length;i++){
                                String s = split[i];
                                String s2="";
                                if (s.length()==8&&flag){
                                    s2 = split[i+1];
                                    flag=false;
                                }
                                if (i==0){
                                    dealFlow.setAccountBodyNumber(s);//帐号
                                    dealFlow.setAccountBodyCard(s);//卡号
                                }else {
                                    if (15<=s.length()&&20>=s.length()){
                                        dealFlow.setAccountBodyCard(s);//交易产品号
                                    }else if (s.length()==8&&s2.length()==6&&flag){
                                        Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(s+s2));
                                        if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                                    }else if (s.length()==8&&s2.length()!=6&&flag){
                                        Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(s));
                                        if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                                    }else if (s.length()==4){
                                        dealFlow.setSerialNumber(s);//交易代码  传票号
                                    }
                                }
                            }
                        }
                    }else if (text.replaceAll(" ","").contains(".")){
                        String[] split = text.split("\\s+");
                        dealFlow.setAccountMoney(new BigDecimal(split[1]));// 交易金额
                        dealFlow.setSurplusMoney(new BigDecimal(split[2]));// 交易后余额
                        // System.out.println(Arrays.toString(split));
                    }else if (!text.contains("。")){
                        String[] split = text.split("\\s+");
                        if (split.length==3){
                            dealFlow.setAccountAddress(split[0]);
                            dealFlow.setTradingOrganizationNumber(split[1]);
                            dealFlow.setContentAbstract(split[2]);
                        }
                        text = br.readLine();
                        String[] rival = text.trim().split("\\s+");
                        if (rival!=null&&rival.length==1) {
                            Pattern p = Pattern.compile("[\\u4e00-\\u9fa5]+|\\d+");
                            Matcher m = p.matcher(rival[0]);
                            while (m.find()) {
                                String group = m.group();
                                if (isInteger(group)) {
                                    dealFlow.setAccountRivalCard(group);
                                    dealFlow.setAccountRivalNumber(group);
                                } else {
                                    dealFlow.setAccountRival(group);
                                }
                            }
                        }
//                        System.out.println(Arrays.toString(split));
                        if (dealFlow.getAccountBodyCard()==null)continue;
                        if (dealFlow.getAccountMoney()!=null&&dealFlow.getAccountMoney().compareTo(new BigDecimal(0))<0)dealFlow.setSign(1);
                        list.add(dealFlow);
                        dealFlow=new DealFlow();
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    /**
     *
     * @author 刘中华
     * @date 2018/11/23 9:42
     * @param [file, javaEncode]
     * @return java.util.List<com.mairuide.bill.DealFlow>
     * @Description  解析开封txt模板
     */
    public List<DealFlow> analysisKaiFengTxt(MultipartFile file,String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String text = null;
            int i=0;
            while((text = br.readLine()) != null){
                i++;
                text=text.trim();
                DealFlow dealFlow = new DealFlow();
                if (i==1) continue;
                if (StringUtils.isBlank(text.replaceAll("\\s+","")))continue;
                String[] split = text.split("\t");
                for (int k=0;k<split.length;k++){
                    if(StringUtils.isBlank(split[k]))continue;
                    switch (k){
                        //case 0:dealFlow.setAccountBodyBank(split[k]);//交易机构号
                        case 1:dealFlow.setAccountBodyBank(split[k]);break;//交易机构名称
                        case 2:dealFlow.setAccountBody(split[k]);break;//户  名
                        case 3:{
                            dealFlow.setAccountBodyNumber(split[k]);//账  号
                            dealFlow.setAccountBodyCard(split[k]);//卡  号
                            break;
                        }
                        case 4:{
                            dealFlow.setContentAbstract(split[k]);
                            if(split[k].contains("入")){
                                dealFlow.setSign(0);
                            }else{
                                dealFlow.setSign(1);
                            }
                            break;//摘  要
                        }
                        case 5:dealFlow.setAccountMoney(new BigDecimal(split[k]));break;//交易金额
                        case 6:dealFlow.setSurplusMoney(new BigDecimal(split[k]));break;//余  额
                        case 7:{
                            dealFlow.setAccountRivalCard(split[k]);//对方账号卡号
                            break;
                        }
                        case 8:dealFlow.setAccountRival(split[k]);break;//对方户名
                        case 9:
                        	Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(split[k]));
                            if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                            break;//交易时间
                        case 10:if (StringUtils.isNotBlank(split[k])){
                        	Date date2 = DateUtils.getDate(DateUtils.getFormatDateString(split[k-1]+split[k]));
                            if(date2!=null) dealFlow.setTradeDate(new Timestamp(date2.getTime()));//日期时间
                            break;//日期时间
                        };//交易时间
                        case 11:dealFlow.setAccountAddress(split[k]);break;//交易柜员
                    }
                    list.add(dealFlow);
                }
            }
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }


    /**
     *
     * @author 刘中华
     * @date 2018/11/23 9:42
     * @param [file, javaEncode]
     * @return java.util.List<com.mairuide.bill.DealFlow>
     * @Description  解析平安txt模板
     */
    public List<DealFlow> analysisPingAnTxt(MultipartFile file,String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String lineTxt = null;
            br.readLine();//去掉第一行
            //这个map存放帐号主体信息
            Map<String,String> map1 = new HashMap<>();
            for (int i=0;i<4;i++){
                lineTxt = br.readLine();
                String [] s=lineTxt.split("\t");
                map1.put(s[1].replace("：",""),s[3]);
                map1.put(s[5].replace("：",""),s[7]);
            }
            //循环内容体
            int l=1;
            while ((lineTxt = br.readLine()) != null) {
                //去掉最后一行
                if (lineTxt.indexOf("共计")>0){
                    break;
                }
                if (l==1){
                    l++;
                    continue;
                }
                DealFlow dealFlow = new DealFlow();
                dealFlow.setAccountBodyNumber(map1.get("账号"));//账  号
                dealFlow.setAccountBody(map1.get("户名"));//户  名
                dealFlow.setAccountBodyCard(map1.get("卡号"));
                dealFlow.setAccountMode(map1.get("存款类型"));
                dealFlow.setAccountBodyBank(map1.get("开户网点"));
                dealFlow.setCurrency(map1.get("币种"));
                lineTxt=lineTxt.trim();
                String[] split = lineTxt.split("\t");
                for (int k=1;k<split.length;k++){
                    switch (k){
                        case 1:
                        	Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(split[k]));
                            if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                            break;//交易时间
                        case 2:dealFlow.setAccountAddress(split[k]);break;//交易网点
                        //case 3:dealFlow.setAccountAddress(split[k]);continue;//起息日
                        case 4:dealFlow.setContentAbstract(split[k]);break;//摘  要
                        case 5:{
                            if (StringUtils.isNotBlank(split[k])){
                                dealFlow.setAccountMoney(new BigDecimal(split[k].replaceAll(",","")));
                            }
                            break;//交易金额
                        }
                        case 7:{
                            if (StringUtils.isNotBlank(split[k])){
                                dealFlow.setSurplusMoney(new BigDecimal(split[k].replaceAll(",","")));
                            }
                            break;//余  额
                        }
                        case 8:dealFlow.setAccountRivalCard(split[k]);break;//对方账号卡号
                        case 9:dealFlow.setAccountRival(split[k]);break;//交易对手
                        case 10:dealFlow.setAccountRivalBank(split[k]);break;//交易对方行名称
                    }
                }
                list.add(dealFlow);
            }
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    /**
     *
     * @author 刘中华
     * @date 2018/11/23 9:42
     * @param [file, javaEncode]
     * @return java.util.List<com.mairuide.bill.DealFlow>
     * @Description  解析平顶山txt模板
     */
    public List<DealFlow> analysisPingDingShanTxt(MultipartFile file,String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String lineTxt = null;
            br.readLine();//去掉第一行
            //主体表头
            String lineHeard = br.readLine();
            String [] s=lineHeard.split("\t");
            //主体信息
            lineTxt = br.readLine();
            String [] s1=lineTxt.split("\t");
            //这个map存放帐号主体信息
            Map<String,String> map1 = new HashMap<>();
            //表头和信息做对应
            for (int i=2;i<s.length;i++){
                map1.put(s[i],s1[i]);
            }
            int l=1;
            //循环内容体
            while ((lineTxt = br.readLine()) != null) {
                //去掉最后一行
                if (lineTxt.indexOf("共计")>0){
                    break;
                }
                if (l==1){
                    l++;
                    continue;
                }
                DealFlow dealFlow = new DealFlow();
                dealFlow.setSurplusMoney(new BigDecimal(map1.get("余额").replaceAll(",","")));
                String[] split= lineTxt.split("\t");
                for (int k=0;k<split.length;k++){
                    if(StringUtils.isBlank(split[k]))continue;
                    switch (k){
                        case 0:{
                            dealFlow.setAccountBodyNumber(split[k]);//账  号
                            dealFlow.setAccountBodyCard(split[k]);//卡  号
                            break;
                        }
                        case 1:dealFlow.setAccountBody(split[k]);break;//户  名
                        case 2:
                        	Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(split[k]));
                            if(date1!=null) dealFlow.setTradeDate(new Timestamp(date1.getTime()));//日期时间
                            break;//交易时间
                        case 3:dealFlow.setSerialNumber(split[k]);break;//交易流水号
                        case 5:dealFlow.setAccountAddress(split[k]);break;//交易机构
                        case 6:dealFlow.setAccountBodyBank(split[k]);break;//机构名称
                        case 8:dealFlow.setAccountBody(split[k]);break;//借方户名
                        case 9:dealFlow.setAccountRivalCard(split[k]);break;//贷方账户
                        case 11:dealFlow.setAccountMoney(new BigDecimal(split[k].replaceAll(",","")));continue;//交易金额
                        case 12:{
                            dealFlow.setSign("借".equals(split[k])?1:0);
                            break;//借贷方
                        }
                        case 14:dealFlow.setContentAbstract(split[k]);break;//摘  要
                    }
                }
                list.add(dealFlow);
            }
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }


    /**
     *
     * @Description  解析农商txt模板
     */
    public List<DealFlow> analysisNongShangTxt(MultipartFile file,String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String lineTxt = null;
            String[] colunms = {"交易机构号","交易机构名称","户名","账号","摘要","交易金额","余额","对方账号卡号","对方户名","交易日期","交易时间","交易柜员"};
            while ((lineTxt = br.readLine()) != null) {
                if (lineTxt.indexOf("：")>0)continue;
                Map<String,String> map = new HashMap<>();
                String[] sp = lineTxt.split("\t");
                if (sp.length<3)continue;
                if(colunms[0].equals(sp[0]))continue;
                for (int i=0;i<sp.length;i++){
                    map.put(colunms[i],sp[i]);
                }
                DealFlow deal = new DealFlow();
                deal.setAccountBody(map.get("户名"));
                deal.setAccountAddress(map.get("交易机构名称"));
                deal.setAccountBodyNumber(map.get("账号"));
                deal.setAccountBodyCard(map.get("账号"));
                deal.setContentAbstract(map.get("摘要"));
                if("入息".equals(map.get("摘要"))){
                    deal.setSign(0);
                }else{
                    deal.setSign(1);
                }
                if (!"".equals(map.get("交易金额"))&&map.get("交易金额")!=null)deal.setAccountMoney(new BigDecimal(map.get("交易金额")));
                if (!"".equals(map.get("余额"))&&map.get("余额")!=null)deal.setSurplusMoney(new BigDecimal(map.get("余额")));
                deal.setAccountRivalNumber(map.get("对方账号卡号"));
                deal.setAccountRivalCard(map.get("对方账号卡号"));
                deal.setAccountRival(map.get("对方户名"));
                String date = map.get("交易日期")+map.get("交易时间");
                Date date1 = DateUtils.getDate(DateUtils.getFormatDateString(date));
                if (date1!=null)deal.setTradeDate(new Timestamp(date1.getTime()));
                if (deal.getAccountBodyCard()==null||"".equals(deal.getAccountBodyCard())){
                    deal.setAccountBodyCard(deal.getAccountBodyNumber());
                }
                if (deal.getAccountRivalCard()==null||"".equals(deal.getAccountRivalCard())){
                    deal.setAccountRivalCard(deal.getAccountRivalNumber());
                }
                list.add(deal);
            }
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    public List<DealFlow> analysisZhongHangDuiGongTxt(MultipartFile file, String javaEncode) {
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,"gbk");
            br = new BufferedReader(reader);
            String text = br.readLine();
            String[] split = text.split("\\|");

            while((text = br.readLine()) != null) {
                Map<String, String> map = new HashMap<>();
                String[] sp = text.split("\\|");
                if (sp.length>2){
                    for (int i = 0; i < split.length; i++) {
                        map.put(split[i].trim(), sp[i].trim());
                    }
                    DealFlow deal = new DealFlow();
                    deal.setAccountBodyNumber(map.get("交易账号"));
                    String date = map.get("交易日期")+" " +map.get("交易时间");
                    Date date1 = DateUtils.getDate(date);
                    if (date1!=null)deal.setTradeDate(new Timestamp(date1.getTime()));
                    deal.setSerialNumber(map.get("交易流水号"));
                    deal.setAccountBodyCard(map.get("真实付款人账号"));
                    deal.setAccountMode(map.get("交易类型描述"));
                    deal.setTellerNumber(map.get("交易柜员"));
                    deal.setTradingOrganizationNumber(map.get("交易机构号"));
                    deal.setAccountAddress(map.get("交易机构名称"));
                    deal.setCurrency(map.get("交易货币"));
                    String s = map.get("借贷标识");
                    if ("C".equals(s)){
                        deal.setSign(0);
                    }else if ("D".equals(s)){
                        deal.setSign(1);
                    }
                    if (!"".equals(map.get("交易金额"))&&map.get("交易金额")!=null)deal.setAccountMoney(new BigDecimal(map.get("交易金额")));
                    if (!"".equals(map.get("交易后余额"))&&map.get("交易后余额")!=null)deal.setSurplusMoney(new BigDecimal(map.get("交易后余额")));
                    deal.setRemarks(map.get("备注"));
                    deal.setContentAbstract(map.get("摘要"));
                    deal.setAccountBody(map.get("真实付款人账户名称"));
                    deal.setAccountBodyBank(map.get("真实付款人账号所属机构名称"));
                    deal.setAccountRival(map.get("真实收款人账户名称"));
                    deal.setAccountRivalCard(map.get("真实收款人卡号"));
                    deal.setAccountRivalNumber(map.get("真实收款人账号"));
                    deal.setAccountRivalBank(map.get("真实收款人所属机构名称"));
                    deal.setInstitutionNumber(map.get("真实收款人账户所属机构号"));

                    if (deal.getAccountBodyCard()==null||"".equals(deal.getAccountBodyCard())){
                        deal.setAccountBodyCard(deal.getAccountBodyNumber());
                    }
                    if (deal.getAccountRivalCard()==null||"".equals(deal.getAccountRivalCard())){
                        deal.setAccountRivalCard(deal.getAccountRivalNumber());
                    }

                    list.add(deal);
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    /**
     *
     * @author 刘中华
     * @date 2018/11/26 15:08
     * @param [file, javaEncode]
     * @return java.util.List<com.mairuide.bill.DealFlow>
     * @Description  解析农行txt模板
     */
    public List<DealFlow> analysisHongHangTxt(MultipartFile file, String javaEncode) {
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        //存放标题头
        Map<Integer,String> map = new HashMap<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String lineTxt = null;
            int i=0;
            while ((lineTxt = br.readLine()) != null) {
                DealFlow deal = new DealFlow();
                lineTxt=lineTxt.trim();
                //System.out.println(lineTxt);
                String[] split = lineTxt.split("\\|");
                if (i==0&&map.size()==0){
                    for(int k=0;k<split.length;k++){
                        map.put(k,split[k]);
                    }
                    continue;
                }
                if (split.length<map.size()-1){
                    continue;
                }
                for (int j=0;j<split.length;j++){
                    if (StringUtils.isBlank(split[j]))continue;
                    if ("null".equals(split[j]))continue;
                    switch (map.get(j)) {
                    //  case "证件号码" :
                    //  case "证件类型" :
                    //  case "客户号" :
                        case "姓名":
                            deal.setAccountBody(split[j]);
                            break;
                        case "账户":
                            deal.setAccountBodyCard(split[j]);
                            deal.setAccountBodyNumber(split[j]);
                            break;
                    //  case "关联账号" :
                    //  case "账户类型" :
                        case "账户余额":
                            deal.setSurplusMoney(new BigDecimal(split[j]));
                            break;
                    //  case "开户日期" :
                    //  case "销户日期" :
                    //  case "账户状态" :
                    }
                }
                deal.setSign(0);
                list.add(deal);
                i++;
            }
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    public List<DealFlow> analysisNongTxt(MultipartFile file, String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        //存放标题头
        Map<Integer,String> map = new HashMap<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String lineTxt = null;
            while ((lineTxt = br.readLine()) != null) {
                String[] split = lineTxt.trim().split("\\s+");
                if ("账号".equals(split[0])){
                    for (int i=0;i<9;i++){//跳读10行
                        br.readLine();
                    }
                    while (!"".equals((lineTxt = br.readLine()).trim())){
                        DealFlow dealFlow = new DealFlow();
                        //第一行数据
                        String[] split1 = lineTxt.trim().split("\\s+");
                        dealFlow.setAccountBodyNumber(split1[0]);
                        Date date = DateUtils.getDate(split1[1]);
                        if (date!=null)dealFlow.setTradeDate(new Timestamp(date.getTime()));
                        dealFlow.setAccountMoney(new BigDecimal(split1[2]));
                        dealFlow.setSurplusMoney(new BigDecimal(split1[3]));
                        //第二行数据
                        lineTxt = br.readLine();
                        Pattern p = Pattern.compile("[\\u4e00-\\u9fa5]+|\\d+");
                        Matcher m = p.matcher(lineTxt.trim());
                        while ( m.find() ) {
                            String group = m.group();
                            if (isInteger(group)){
                                dealFlow.setAccountRivalCard(group);
                            } else {
                                dealFlow.setAccountRival(group);
                            }
                        }
                        //第三行数据
                        dealFlow.setContentAbstract(br.readLine().trim());
                        //第四行数据
                        lineTxt = br.readLine();
                        String[] split2 = lineTxt.trim().split("\\s+");
                        if (split2.length==3){
                            dealFlow.setSerialNumber(split2[1]);
                            dealFlow.setAccountRivalBank(split2[2]);
                        }else {
                            dealFlow.setSerialNumber(split2[1]);
                            dealFlow.setInstitutionNumber(split2[2]);
                            dealFlow.setAccountRivalBank(split2[3]);
                        }
                        //第五行数据
                        String sign = br.readLine().trim();
                        if ("C0".equals(sign)){
                            dealFlow.setSign(0);
                        }else if ("D0".equals(sign)){
                            dealFlow.setSign(1);
                        }
                        if (dealFlow.getAccountBodyCard()==null||"".equals(dealFlow.getAccountBodyCard())){
                            dealFlow.setAccountBodyCard(dealFlow.getAccountBodyNumber());
                        }
                        list.add(dealFlow);
                    }
                }
            }
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    public List<DealFlow> zhuDangChaxun(MultipartFile file, String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        //存放标题头
        Map<Integer,String> map = new HashMap<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String lineTxt = null;
            while ((lineTxt = br.readLine()) != null) {
                String[] split = lineTxt.trim().split("\\s+");
                if ("帐号".equals(split[0])){
                    for (int i=0;i<5;i++){//跳读5行
                        br.readLine();
                    }
                    while (!"".equals((lineTxt = br.readLine()).trim())){
                        DealFlow dealFlow = new DealFlow();
                        //第一行数据
                        String[] split1 = lineTxt.trim().split("\\s+");
                        dealFlow.setAccountBodyNumber(split1[0]);
                        dealFlow.setAccountBodyCard(split1[1]);
                        Date date = DateUtils.getDate(split1[2]);
                        if (date!=null)dealFlow.setTradeDate(new Timestamp(date.getTime()));


                        //第二行数据
                        lineTxt = br.readLine();
                        String[] split2 = lineTxt.trim().split("\\s+");
                        if (split2.length==2&&split2[0].contains(".")){
                            dealFlow.setAccountMoney(new BigDecimal(split2[0]));
                            dealFlow.setSurplusMoney(new BigDecimal(split2[1]));
                        }else if (split2.length==3){

                            dealFlow.setSerialNumber(split2[0]);
                            dealFlow.setAccountMoney(new BigDecimal(split2[1]));
                            dealFlow.setSurplusMoney(new BigDecimal(split2[2]));
                        }

                        //第三行数据
                        lineTxt = br.readLine();
                        String[] split3 = lineTxt.trim().split("\\s+");
                        dealFlow.setAccountAddress(split3[0]);
                        if (split3.length==3)dealFlow.setContentAbstract(split3[2]);


                        //第四行数据
                        lineTxt = br.readLine();
                        Pattern p = Pattern.compile("[\\u4e00-\\u9fa5]+|\\d+");
                        Matcher m = p.matcher(lineTxt.trim());
                        while ( m.find() ) {
                            String group = m.group();
                            if (isInteger(group)){
                                dealFlow.setAccountRivalCard(group);
                            } else {
                                dealFlow.setAccountRival(group);
                            }
                        }

                        if (dealFlow.getAccountBodyCard()==null||"".equals(dealFlow.getAccountBodyCard())){
                            dealFlow.setAccountBodyCard(dealFlow.getAccountBodyNumber());
                        }

                        list.add(dealFlow);
                    }
                }
            }
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    public List<DealFlow> zZGongAn(MultipartFile file, String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        //存放标题头
        Map<Integer,String> map = new HashMap<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String lineTxt = null;
            String bodyNumber = null;
            while ((lineTxt = br.readLine()) != null) {
                if (lineTxt.contains("查询的户名（账号）："))bodyNumber = lineTxt.split("：")[1];
                String[] split = lineTxt.trim().split("\\s+");
                if ("合约号".equals(split[0].trim())){
                    for (int i=0;i<7;i++){//跳读7行
                        br.readLine();
                    }
                    while (!"".equals((lineTxt = br.readLine()).trim())){
                        DealFlow dealFlow = new DealFlow();
                        //第一行数据
                        byte[] buf1 = lineTxt.getBytes("gbk");
                        dealFlow.setAccountBodyNumber(new String(buf1, 0, 19, "gbk").trim());
                        dealFlow.setAccountBodyCard(new String(buf1, 19, 33, "gbk").trim());
                        dealFlow.setAccountBodyBank(new String(buf1, 52, 8, "gbk").trim());


                        //第二行数据
                        lineTxt = br.readLine();
                        dealFlow.setAccountBody(lineTxt);

                        //第三行数据
                        lineTxt = br.readLine();
                        byte[] buf3 = lineTxt.getBytes("gbk");
                        String date = new String(buf3, 54, 10, "gbk").trim();
                        Date date1 = DateUtils.getDate(date);
                        if (null!=date1)dealFlow.setTradeDate(new Timestamp(date1.getTime()));


                        //第四行数据
                        lineTxt = br.readLine();
                        byte[] buf4 = lineTxt.getBytes("gbk");
                        String money = new String(buf4, 0, 24, "gbk").trim();
                        dealFlow.setSurplusMoney(new BigDecimal(money));

                        if (dealFlow.getAccountBodyCard()==null||"".equals(dealFlow.getAccountBodyCard())){
                            dealFlow.setAccountBodyCard(dealFlow.getAccountBodyNumber());
                        }

                        list.add(dealFlow);
                    }
                }
            }
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    public List<DealFlow> weiXin(MultipartFile file, String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        //存放标题头
        Map<Integer,String> map = new HashMap<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String lineTxt = br.readLine();
            while ((lineTxt = br.readLine()) != null) {
                lineTxt = lineTxt+" ";
                String[] split = lineTxt.split("\\t");
                DealFlow dealFlow = new DealFlow();
                dealFlow.setAccountBodyCard(split[0].substring(1,split[0].length()-1));
                dealFlow.setAccountBodyNumber(split[0].substring(1,split[0].length()-1));
                dealFlow.setSerialNumber(split[1].substring(1,split[1].length()-1));
                if("入".equals(split[2])) {
                    dealFlow.setSign(0);
                    dealFlow.setAccountRivalCard(split[10]);
                    dealFlow.setAccountRivalNumber(split[10]);
                }else {
                    dealFlow.setSign(1);
                    dealFlow.setAccountRivalCard(split[12]);
                    dealFlow.setAccountRivalNumber(split[12]);
                }
                dealFlow.setContentAbstract(split[3]);
                int a = Integer.parseInt(split[4]);
                dealFlow.setAccountMoney(new BigDecimal(String.valueOf(a/100)));
                int b = Integer.parseInt(split[5]);
                dealFlow.setSurplusMoney(new BigDecimal(b/100));
                Date date = DateUtils.getDate(split[6]);
                dealFlow.setTradeDate(new Timestamp(date.getTime()));
                dealFlow.setAccountMode(split[9]);
                dealFlow.setRemarks(split[7]+" "+split[9]);
                if ("财付通(1000000000)".equals(split[9])){
                    dealFlow.setAccountRival("财付通提现");
                    dealFlow.setAccountRivalNumber("1000000000");
                    dealFlow.setAccountRivalCard("1000000000");
                }
                list.add(dealFlow);
            }
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    public List<DealFlow> nongHangAtm(MultipartFile file, String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        List<DealFlow> list = new ArrayList<>();
        //存放标题头
        Map<Integer,String> map = new HashMap<>();
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String lineTxt = br.readLine();
            while ((lineTxt = br.readLine()) != null) {
                String[] split = lineTxt.split("\\|");
                DealFlow dealFlow = new DealFlow();
                if("收款方".equals(split[0])) {
                    dealFlow.setSign(0);
                }else if ("付款方".equals(split[0])){
                    dealFlow.setSign(1);
                } else {
                    continue;
                }
                dealFlow.setAccountBodyCard(split[1]);
                dealFlow.setAccountBodyNumber(split[1]);
                dealFlow.setAccountRivalCard(split[2]);
                dealFlow.setAccountRivalNumber(split[2]);
                Date date = DateUtils.getDate(split[3]);
                if (date!=null)dealFlow.setTradeDate(new Timestamp(date.getTime()));

                dealFlow.setAccountMoney(new BigDecimal(split[5]));
                dealFlow.setTellerNumber(split[6]);
                dealFlow.setSerialNumber(split[7]);


                list.add(dealFlow);
            }
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return list;
        }
    }

    public OpenaccountInfo weiXinInfo(MultipartFile file, String javaEncode){
        InputStream inputStream=null;
        InputStreamReader reader=null;
        BufferedReader br=null;
        OpenaccountInfo op = null;
        try {
            inputStream = file.getInputStream();
            reader= new InputStreamReader(inputStream,javaEncode);
            br = new BufferedReader(reader);
            String lineTxt = br.readLine();
            if ((lineTxt = br.readLine()) != null) {
                lineTxt = lineTxt+" ";
                String[] split = lineTxt.split("\\t");
                op = new OpenaccountInfo();
                op.setTradeCard(split[1]);
                op.setTradeAccount(split[1]);
                op.setAccountOwner(split[2]);
                if (!"".equals(split[4]))op.setIdNumber(split[4].substring(1,split[4].length()-1));
                op.setOpenAccountTime(new Timestamp(DateUtils.getDate(split[3]).getTime()));
            }
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            closeStream(inputStream,reader,br);
            return op;
        }
    }

    /**
     *
     * @author 刘中华
     * @date 2018/11/22 15:29
     * @param [str]
     * @return boolean
     * @Description 判断是否是数字或者字母组合类型
     */
    public static boolean isNumeric(String str){
        Pattern pattern = Pattern.compile("\\w+");
        return pattern.matcher(str).matches();
    }
    /**
     * 判断字符串是否为数字
     * @param str
     * @return
     */
    private boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }

    /**
     *
     * @author 刘中华
     * @date 2018/11/22 13:39
     * @param [inputStream, inputStreamReader, bufferedReader]
     * @return void
     * @Description 关闭流操作
     */
    public static void closeStream(InputStream inputStream,InputStreamReader inputStreamReader,BufferedReader bufferedReader) {
        try {
            if (bufferedReader!=null){
                bufferedReader.close();
            }
            if (inputStreamReader!=null){
                inputStreamReader.close();
            }
            if (inputStream!=null){
                inputStream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    public static void main(String[] arg) throws  Exception{
        // 匹配包含"你"或"锤子"
        System.out.println("哎呀，你在搞什么锤子啊？".matches(".*(你|锤子).*"));
        HashMap<Object, Object> map = new HashMap<>();
        String ss="证件号码|证件类型|客户号|姓名|账户|关联账号|账户类型|账户余额|开户日期|销户日期|账户状态";
        String a="410403199703195659|无记录| | | | | |0.00| | |";
        String[] split = ss.split("\\|");
        for (String s:split){
            System.out.println(s);
        }
        System.out.println(a.split("\\|").length);

    }


}
